package hc.bre

import static org.junit.jupiter.api.Assertions.*

import hc.bre.clas.yesno.YesNoBuilder
import hc.bre.clas.yesno.YesNoDefinition
import hc.bre.cmn.RuleDefinition
import hc.bre.cmn.RuleScriptBuilder
import hc.bre.cmn.RuleScriptBuilder.ClassNameMode
import hc.bre.project.ProjectDefinition
import org.junit.jupiter.api.Test

@groovy.transform.CompileStatic
class ScriptBuilderTest {
	@Test
	void ScriptBuilderIndent() {
		RuleScriptBuilder sb = new RuleScriptBuilder() {
			@Override
			public String build() {
				return null;
			}
		}
		String nl;
		
		nl = sb.nl
		assert nl=='\n';
		
		sb.nested { 
			nl = sb.nl
			assert nl=='\n\t';
			sb.nested { 
				nl = sb.nl
				assert nl=='\n\t\t';
			}
			nl = sb.nl
			assert nl=='\n\t';
		}
	}
	
String jsonText='''
{
  "rid" : 167,
  "rtype" : "rule:clas:yesno",
  "rname" : "逻辑是否分类2",
  "rpath" : "xsxdjc/class9/LuoJiShiFuFenLei2",
  "rversion" : 8,
  "script" : "true",
  "rmemo" : "",
  "rtest" : "{}",
  "list" : [ {
    "id" : 1,
    "code" : "yes",
    "name" : "是"
  }, {
    "id" : 0,
    "code" : "no",
    "name" : "否"
  } ]
}
'''
		@Test
		void fullClassName() {
			 
			YesNoDefinition ruleDef = new YesNoDefinition()
			ruleDef.load(hc.Util.jsonRead(jsonText));
			YesNoBuilder builder = new YesNoBuilder();
			builder.forRule(ruleDef);
			builder.classNameMode = ClassNameMode.SHORT;
			String script = builder.build();
//			GroovyShell shell = new GroovyShell();
//			shell.evaluate(script + "")
			println script;
			
		}

}
